package com.xlf.service.base.controller.admin;

import com.xlf.common.core.pojo.mode.AjaxResult;
import com.xlf.common.core.pojo.mode.BaseController;
import com.xlf.pojo.base.Contest;
import com.xlf.pojo.base.ContestProblem;
import com.xlf.pojo.base.ContestRegister;
import com.xlf.pojo.base.ProblemList;
import com.xlf.service.base.service.ContestService;
import com.xlf.service.base.service.ProblemListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author xlf 2734029211@qq.com
 * @Date 2023/12/16 10:34
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("/base/admin/contest")
public class AdminContestController extends BaseController {

    @Autowired
    ContestService contestService;

    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('base:admin:contest:list')")
    public AjaxResult list(Contest contest){
        startPage();
        return success(getDataTable(contestService.getList(contest)));
    }

    @GetMapping("/getProblemList/{id}")
    @PreAuthorize("@ss.hasPermi('base:admin:contest:list')")
    public AjaxResult getProblemList(@PathVariable(value = "id") Long id){
        return success(contestService.getProblemList(id));
    }

    @PostMapping("/addContestProblem")
    @PreAuthorize("@ss.hasPermi('base:admin:contest:saveOrUpdate')")
    public AjaxResult addContestProblem(@RequestBody List<ContestProblem> contestProblems){
        contestService.addContestProblem(contestProblems);
        return success();
    }

    @PostMapping("/addRegisterUser")
    @PreAuthorize("@ss.hasPermi('base:admin:contest:saveOrUpdate')")
    public AjaxResult addRegisterUser(@RequestBody List<ContestRegister> contestRegisters){
        contestService.addRegisterUser(contestRegisters);
        return success();
    }

    @PostMapping("/updateContestProblem")
    @PreAuthorize("@ss.hasPermi('base:admin:contest:saveOrUpdate')")
    public AjaxResult updateContestProblem(@RequestBody ContestProblem contestProblem){
        contestService.updateContestProblem(contestProblem);
        return success();
    }

    @GetMapping("/getRegisterUserList/{id}")
    @PreAuthorize("@ss.hasPermi('base:admin:contest:list')")
    public AjaxResult getRegisterUserList(@PathVariable(value = "id") Long id){
        startPage();
        return success(getDataTable(contestService.getRegisterUserList(id)));
    }

    @PostMapping("/saveOrUpdate")
    @PreAuthorize("@ss.hasPermi('base:admin:contest:saveOrUpdate')")
    public AjaxResult saveOrUpdate(@RequestBody Contest contest){
        return success(contestService.saveOrUpdate_(contest));
    }


    @GetMapping("/query/{id}")
    @PreAuthorize("@ss.hasPermi('base:admin:contest:query')")
    public AjaxResult query(@PathVariable(value = "id") Long id){
        return success(contestService.getConTest(id));
    }

    @DeleteMapping("/delete")
    @PreAuthorize("@ss.hasPermi('base:admin:contest:delete')")
    public AjaxResult delete(@RequestBody List<Long> ids){
        contestService.delete(ids);
        return success("删除成功！");
    }

    @PutMapping("/disabled")
    @PreAuthorize("@ss.hasPermi('base:admin:contest:disabled')")
    public AjaxResult updateStatus(@RequestBody Contest contest){
        return success(contestService.updateStatus(contest));
    }
}

